		
		***********************************
		* Table 1: Descriptive Statistics *
		***********************************
			
		use "data/Final_data.dta", clear
		
		* First Step, Go get the population-level descriptive Stats in the CENSUS2016
		preserve
		use "data/DescStatsCensus2016.dta", clear
		
		estpost summarize group male_pct married_comlaw_pct wid_sep_div_pct never_married_pct educ_hs_less_pct educ_some_uni_pct educ_bach_more_pct totinc_i_t [aw=WEIGHT], detail
		est store pop2016
				
		* Second Step, Go get the TFSA/RRSP data in the SFS2016
		use "data/DescStatsSFS2016.dta", clear
		
		gen ind_rrsp_amt_t=cond_rrsp/1000 
		gen ind_tfsa_amt_t=cond_tfsa/1000 
		
		estpost summarize  ind_rrsp_amt_t ind_tfsa_amt_t [aw=wgt], detail
		est store SFS2016

		restore
									
		* Third Step, get the demographic variables in our sample
		label variable age "\(\qquad\) Age"		
		gen totinc_i_t = totinc_i/1000
		label variable totinc_i_t "\(\qquad\) Annual income ('000 \\$)"	
		gen totspend_i_t=totspend_i/1000
		label variable totspend_i_t "\(\qquad\) Annual spending ('000 \\$)" 
		
		gen male_pct=male*100
		label variable male_pct "\(\qquad\) Male (\%)"
		
		gen ind_rrsp_amt_t=ind_rrsp_amt_i/1000
		label variable ind_rrsp_amt_t "\(\qquad\) RRSP amount ('000 \\$)"

		gen ind_tfsa_amt_t=ind_tfsa_amt_i/1000
		label variable ind_tfsa_amt_t "\(\qquad\) TFSA amount ('000 \\$)"	
		
		* 3 level education
		gen educ_hs_less=(educ==1|educ==2)
		gen educ_hs_less_pct=educ_hs_less*100
		label variable educ_hs_less_pct "\(\qquad\) High school or less (\%)"
		
		gen educ_some_uni=(educ==3|educ==4|educ==5)
		gen educ_some_uni_pct=educ_some_uni*100
		label variable educ_some_uni_pct "\(\qquad\) College or some university (\%)"
		
		gen educ_bach_more=(educ==6|educ==7)
		gen educ_bach_more_pct=educ_bach_more*100
		label variable educ_bach_more_pct "\(\qquad\) Bachelor degree or more (\%)"
		
		* Answers to Fin lit questions
		* Set up the financial literacy measures
		gen finlit_int_good=(finlit_interest==1) 
		gen finlit_infl_good=(finlit_inflation==3)  
		gen finlit_risk_good=(finlit_risk==2)
		
		gen finlit_index=finlit_int_good+finlit_infl_good+finlit_risk_good
		gen finlit1=finlit_index==1
		gen finlit1_pct=finlit1*100
		label variable finlit1_pct "\(\qquad\) 1 correct answer (\%)"
		
		gen finlit2=finlit_index==2
		gen finlit2_pct=finlit2*100
		label variable finlit2_pct "\(\qquad\) 2 correct answers (\%)"
		
		gen finlit3=finlit_index==3
		gen finlit3_pct=finlit3*100
		label variable finlit3_pct "\(\qquad\) 3 correct answers (\%)"
		
		* Marital status
		gen married_comlaw=(marstat==1|marstat==2)
		gen married_comlaw_pct=married_comlaw*100
		label variable married_comlaw_pct "\(\qquad\) Married or common-law (\%)"
		
		gen wid_sep_div=(marstat==3|marstat==4|marstat==5)
		gen wid_sep_div_pct=wid_sep_div*100
		label variable wid_sep_div_pct "\(\qquad\) Widowed, separated or divorced (\%)"
		
		gen never_married=marstat==6
		gen never_married_pct=never_married*100
		label variable never_married_pct "\(\qquad\) Never married (\%)"
		
		label variable delta "\(\qquad\) \(\beta\)"
		label variable sigma "\(\qquad\) \(\sigma\)"
		
		
		global demog age male_pct married_comlaw_pct wid_sep_div_pct never_married_pct educ_hs_less_pct educ_some_uni_pct educ_bach_more_pct ///
		totinc_i_t totspend_i_t ind_rrsp_amt_t ind_tfsa_amt_t finlit1_pct finlit2_pct finlit3_pct sigma delta 
		
		estpost summarize $demog [aw=weight] if tag, detail
		est store A
			
		
		gen treatvidslide=(intervention==3) if intervention!=2 
		gen treatvid=(intervention==3) if intervention!=1
		
		estpost ttest $demog if tag, by(treatvidslide) 
		est store tt1
		estpost ttest $demog if tag, by(treatvid)
		est store tt2
		
		
		esttab pop2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", replace f plain  ///
		order(age ) keep(age) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		mgroups("Population" "Sample" "Diff. w/ control (std. err.)" , pattern(1 1 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		mtitle ("Mean (std. dev.)" "Mean (std. dev.)"  "Means-testing arm" "Tax arm") star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(1 1 0))  se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
			
		esttab pop2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order( male_pct married_comlaw_pct wid_sep_div_pct never_married_pct educ_hs_less_pct educ_some_uni_pct educ_bach_more_pct ) keep (male_pct married_comlaw_pct wid_sep_div_pct never_married_pct educ_hs_less_pct educ_some_uni_pct educ_bach_more_pct) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(0 0 0)) se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
			
		esttab pop2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order( totinc_i_t totspend_i_t ) keep (totinc_i_t totspend_i_t) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(1 1 0)) se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
						
		esttab SFS2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order( ind_rrsp_amt_t ) keep (ind_rrsp_amt_t) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(1 1 0)) se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
						
		esttab SFS2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order(ind_tfsa_amt_t ) keep (ind_tfsa_amt_t) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(1 1 0)) se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
		
		esttab SFS2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order( finlit1_pct finlit2_pct finlit3_pct ) keep ( finlit1_pct finlit2_pct finlit3_pct) sub(\_ _) ///
		refcat(age "\emph{A. Demographics}" totinc_i_t "\emph{B. Income and Savings}" finlit1_pct "\emph{C. Financial Literacy}", nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(0 0 0)) se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
				
		esttab pop2016 A tt1 tt2 using "tables_figures/demog_ttest.tex", append f plain  ///
		order(sigma delta ) keep (delta sigma) sub(\_ _) ///
		refcat(sigma "\emph{D. Preferences}"  , nolabel)  ///
		nomtitle star(* 0.10 ** 0.05 *** 0.01) /// 
		cells("mean(fmt(%12.2fc) pattern (1 1 0)) b(fmt(%12.2fc)star pattern (0 0 1))" "sd(fmt(%12.2fc)par pattern(1 1 0))  se(fmt(%12.2fc)par pattern(0 0 1))" ) nonum nogaps eqlabels(none) label collabels(none) noobs
				  
		
		
		*******************************************
		* Table 2: Answers to Knowledge Questions *
		*******************************************
			
		* Recode the answer to knowledge questions 
		* 1 is right, 0 is wrong/don't know/ refuse
		
		gen q37=(know_deductible==1)
		gen q38=(know_withdaw_tax==1)
		gen q39=(know_returns_tax==4)
		gen q40=(know_penalty==4)
		gen q41=(know_room==2)
		
		gen know_score=round((q37+q38+q39+q40+q41)/5, 0.1)
	
		label def know_deductible2 1 "\(\qquad\) Correct : RRSP only" 2 "\(\qquad\) Wrong: TFSA only" 3 "\(\qquad\) Wrong : both" 4 "\(\qquad\) Wrong: none" 7 "\(\qquad\) Don't Know" 8 "\(\qquad\) Refuse"
		label def know_withdaw_tax2 1 "\(\qquad\) Correct : RRSP only" 2 "\(\qquad\) Wrong: TFSA only" 3 "\(\qquad\) Wrong : both" 4 "\(\qquad\) Wrong: none" 7 "\(\qquad\) Don't Know" 8 "\(\qquad\) Refuse"
		label def know_returns_tax2 1 "\(\qquad\) Wrong : RRSP only" 2 "\(\qquad\) Wrong: TFSA only" 3 "\(\qquad\) Wrong : both" 4 "\(\qquad\) Correct: none" 7 "\(\qquad\) Don't Know" 8 "\(\qquad\) Refuse"
		label def know_penalty2 1 "\(\qquad\) Wrong : RRSP only" 2 "\(\qquad\) Wrong: TFSA only" 3 "\(\qquad\) Wrong : both" 4 "\(\qquad\) Correct: none" 7 "\(\qquad\) Don't Know" 8 "\(\qquad\) Refuse"
		label def know_room2 1 "\(\qquad\) Wrong : RRSP only" 2 "\(\qquad\) Correct: TFSA only" 3 "\(\qquad\) Wrong : both" 4 "\(\qquad\) Wrong: none" 7 "\(\qquad\) Don't Know" 8 "\(\qquad\) Refuse"

		foreach var of varlist know_deductible know_withdaw_tax know_returns_tax know_penalty know_room{

		label val  `var' `var'2
		}
		
		* Export the raw answers to each questions
		estpost tab know_deductible if tag 
		est store know_deductible 
		
		esttab know_deductible using "tables_figures/know_all.tex", replace f plain   ///
		refcat (1 "\hline \\  Q1. According to you, are the contributions made to an RRSP or to a TFSA deductible \\ from taxable income?", nolabel) ///
		cells("b(label(Frequency) fmt(%12.2gc)) pct(label(Percent) fmt(2)) cumpct(label(Cum. Percent) fmt(2))")  ///
		varlabels(`e(labels)')  varwidth(20) nonumber nomtitle noobs drop(Total) 

		estpost tab know_withdaw_tax if tag
		est store know_withdaw_tax
		
		esttab know_withdaw_tax using "tables_figures/know_all.tex", append f plain   ///
		refcat (1 "\\ Q2. According to you, when money is withdrawn from an RRSP or from a TFSA, is it subject to \\income tax in the year of the withdrawal? Assume the withdrawn amount is not used for the \\ Home Buyers’ Plan (HBP) or the Lifelong Learning Plan (LLP).", nolabel) ///
		cells("b(label() fmt(%12.2gc)) pct(label() fmt(2)) cumpct(label() fmt(2))")  ///
		mlabels(none) collabels(none) varlabels(`e(labels)', blist(Total ""))  varwidth(20) nonumber nomtitle noobs drop(Total)
		
		estpost tab know_returns_tax if tag
		est store know_returns_tax
		
		esttab know_returns_tax using "tables_figures/know_all.tex", append f plain   ///
		refcat (1 "\\ Q3. Money invested in an RRSP or in a TFSA can generate returns in the form of interest,  \\ dividends or capital gains. According to you, are these returns subject to income tax in the \\ year during which they were generated?", nolabel) ///
		cells("b(label(Frequency) fmt(%12.2gc)) pct(label(Percent) fmt(2)) cumpct(label(Cum. Percent) fmt(2))") ///
		mlabels(none) collabels(none) varlabels(`e(labels)', blist(Total ""))  varwidth(20) nonumber nomtitle noobs drop(Total)
		
		estpost tab know_penalty if tag
		est store know_penalty
		
		esttab know_penalty using "tables_figures/know_all.tex", append f plain   ///
		refcat (1 "\\ Q4. According to you, is there a penalty associated with withdrawing money from an RRSP or \\ from a TFSA before retirement? Assume the withdrawn amount is not used for the Home Buyers’ \\ Plan (HBP) or the Lifelong Learning Plan (LLP).", nolabel) ///
		cells("b(label(Frequency) fmt(%12.2gc)) pct(label(Percent) fmt(2)) cumpct(label(Cum. Percent) fmt(2))")  ///
		mlabels(none) collabels(none) varlabels(`e(labels)', blist(Total ""))  varwidth(20) nonumber nomtitle noobs drop(Total)
		
		estpost tab know_room if tag
		est store know_room
		
		esttab know_room using "tables_figures/know_all.tex", append f plain   ///
		refcat (1 "\\ Q5. Let’s assume you withdraw \\$1,000 from an RRSP or from a TFSA. According to you, will this withdrawn \\ amount be added to your future contribution room? ", nolabel) /// 
		cells("b(label(Frequency) fmt(%12.2gc)) pct(label(Percent) fmt(2)) cumpct(label(Cum. Percent) fmt(2))")   ///
		mlabels(none) collabels(none) varlabels(`e(labels)', blist(Total ""))  varwidth(20) nonumber nomtitle noobs drop(Total)
	
		
		********************************************************************
		* Table OA.2: Determinants of Knowledge Score in the Control Group *
		********************************************************************
		
		gen totinc_i_100000=totinc_i/100000
		
		
		* In the control group
		reg know_score c.age##c.age i.ind_rrsp i.ind_tfsa if intervention==3 & tag
		est store kscore_control_1
		
		reg know_score c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000  if intervention==3 & tag
		est store kscore_control_2
		
		reg know_score c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.educ_some_uni i.educ_bach_more if intervention==3 & tag
		est store kscore_control_3
		
		reg know_score c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.educ_some_uni i.educ_bach_more i.finlit_index if intervention==3 & tag
		est store kscore_control_4
		
		esttab kscore_control_1 kscore_control_2 kscore_control_3 kscore_control_4 using "tables_figures/kscore_control.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "(1)" "(2)" "(3)" "(4)", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(r2 N , fmt(3  %12.0fc )  labels(`"\\ \(R^{2}\)"'  `"{Observations}"'    ))  ///
		refcat(1.wid_sep_div "\parbox{5.5cm}{\textbf{Marital Status} \\[2.5pt] (Married ommitted)}"  1.educ_some_uni "\parbox{5.5cm}{\textbf{Education} \\[2.5pt] (High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2.5pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) ///
		order(1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index ) ///
		keep( 1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index ) ///
		sub(\_ _  age "Age" c.Age#c.Age "Age\(^2\)" 1.wid_sep_div "Widow, separated or divorce" 1.never_married "Never married" totinc_i_100000 "Annual income (100,000's)" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree or more" ///
		1.finlit_index "1 correct answer" 2.finlit_index "2 correct answers" 3.finlit_index "3 correct answers" 1.ind_rrsp "Has RRSP" 1.ind_tfsa "Has TFSA" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) 
		
		
		***************************************************
		* Table 3: Is the answer to the question correct? *
		***************************************************
		
		* Simple logit 1 is correct, 0 is wrong or don't know
		foreach x in q37 q38 q39 q40 q41 know_score {
			probit `x' ib(3).intervention if tag
			scalar r2=e(r2_p)
			margins, dydx(1.intervention 2.intervention) post
			sum `x' if intervention==3 & tag
			estadd scalar base=r(mean)
			estadd scalar r2=r2
			est store `x'
		}
		
		esttab q37 q38 q39 q40 q41 know_score using "tables_figures/rrsp_questions.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "\parbox{2.3cm}{\centering Contributions \\ Deductible?}" "\parbox{2.1cm}{\centering Withdrawals \\ Taxed?}"  "\parbox{1.9cm}{\centering Returns \\ Taxed?}" ///
		"\parbox{1.9cm}{\centering Withdrawal \\ Penalty?}" "\parbox{2.1cm}{\centering Contribution \\ Room?}" "Score/100", pattern(1 1 1  1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(base r2 N , fmt(2 3  %12.0fc )  labels(`"Control avg."' `"\\ \(R^{2}\)"'  `"{Observations}"'    ))  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) sub(\_ _ ) ///
		order(1.intervention 2.intervention ) ///
		keep(1.intervention 2.intervention  )  ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) label
		
						
	
		
		* Calculate if RRSP or TSFA is optimal based on the different optimality measures
		* 0 for RRSP, 1 for TFSA
						
		rename scn_choice choice
		recode choice (1=0) (2=1)		
		
		label def choice 0 "\(\qquad\)RRSP" 1 "\(\qquad\)TFSA" 
		label val choice choice
		
		
		******************************************************
		**** Optimality based on marginal tax rates only  ****
		**** 		(PERFECT ADJUSTMENT RULE)			  ****
		******************************************************
		
		gen optimv1=.
			replace optimv1=0 if  (tau2 <  tau1) 
			replace optimv1=1 if  (tau2 >= tau1) 
			
		label var optimv1 "Optimality Based on Marginal Tax Rates for Scenario `x'"
		label def optimv1 0 "\(\qquad\)RRSP" 1 "\(\qquad\)TFSA" 
		label val optimv1 optimv1
		
		gen rightv1=(choice==optimv1) if !missing(choice) & !missing(optimv1)	
		
		* Calculate the shortfall in percentage
		
		* 1) Generate the difference in percentage between RRSP and TFSA
		gen perc_mistake=cond(optimv1==0&rightv1==0,(tau1-tau2)/(1-tau2),0)
		replace perc_mistake=(tau2-tau1)/(1-tau1) if optimv1==1&rightv1==0
		
		* 2) Calculate it in dollars
		gen dollar_mistake=.
		replace dollar_mistake=0 if rightv1==1
		replace dollar_mistake=-X * (tau1-tau2)/(1-tau1) if rightv1==0 & optimv1==1
		replace dollar_mistake=X * (tau1-tau2)/(1-tau1) if rightv1==0 & optimv1==0
	
		* Get the average welfare loss in $ across scenarios		
		egen dollar_average=mean(dollar_mistake), by(id)
		
		********************************************
		**** Optimality based on utility values ****
		**** 	(IMPERFECT ADJUSTMENT RULE)		****
		********************************************
	
		* Utility values
		gen uRRSP= (S+tau1*X)^(1-sigma) / (1-sigma) + delta * 0.98^(t-1) * (RS+(1-tau2)*Y )^(1-sigma) / (1-sigma)
		gen uTFSA= (S)^(1-sigma)/(1-sigma) + delta * 0.98^(t-1) *  (RS+Y )^(1-sigma)/(1-sigma) 
							
		gen optimv2=.
			replace optimv2= 0 if uRRSP> uTFSA & !missing(uRRSP) & !missing(uTFSA)
			replace optimv2= 1 if uRRSP<=uTFSA & !missing(uRRSP) & !missing(uTFSA)
			
		label var optimv2 "Optimality Based on Utility Values for Scenario `x'"
		label def optimv2 0 "\(\qquad\)RRSP" 1 "\(\qquad\)TFSA" 
		label val optimv2 optimv2	
		
		gen rightv2=(choice==optimv2) if !missing(choice) & !missing(optimv2)

				
		**************************************************************
		* Calculating the welfare loss from making the wrong choice...
		**************************************************************
		
		gen V_choice=cond(choice==1, uTFSA, uRRSP)
		gen V_optim=cond(optimv2==1, uTFSA, uRRSP)
		gen V_delta=V_choice-V_optim
		
		gen u_c1=((S)^(1-sigma))/(1-sigma)
		
		gen pi= S - ((V_delta+u_c1)*(1-sigma)) ^( 1 / (1-sigma) )
			
		* Get the average welfare loss in $$ across scenarios		
		egen pi_average=mean(pi), by(id)
		
		
		*****************************************************************
		* Table 4: Respondents' Choices in Each Scenario and Optimality *
		*****************************************************************
				
		foreach x in 1 2 3 4 5 6 {			
			estpost tab choice if scn==`x'
			est store scn_`x'
		}			
				
		* What is optimal for people to choose, given different way of defining optimality
				
		foreach x in 1 2 3 4 5 6 {	
			foreach y in 1 2 {
				estpost tab optimv`y' if scn==`x'
				est store optimv`y'_`x'
			}
		}
										
		esttab optimv1_1 optimv1_2 optimv1_3 optimv1_4 optimv1_5 optimv1_6   using "tables_figures/optim.tex", replace f plain   ///
		mgroups( "Scn1" "Scn2" "Scn3" "Scn4" "Scn5" "Scn6", pattern(1 1 1 1 1 1  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		refcat(\(\qquad\)RRSP "\emph{A. What is optimal? (Perfect adjustment rule)}", nolabel) unstack mlabels(none) collabels(none) drop(Total)  ///
		cells("pct(label(Percent) fmt(2))") nomtitles   varlabels(`e(labels)')  varwidth(20) nonumber  eqlabels(none)  noobs
		
		esttab optimv2_1 optimv2_2 optimv2_3 optimv2_4 optimv2_5 optimv2_6 using "tables_figures/optim.tex", append f plain   ///
		refcat(\(\qquad\)RRSP "\emph{B. What is optimal? (Imperfect adjustment rule)}", nolabel) unstack   mlabels(none) collabels(none)  drop(Total) ///
		cells("pct(label(Percent) fmt(2))") nomtitles   varlabels(`e(labels)' )  varwidth(20) nonumber   eqlabels(none)  noobs
		
		esttab scn_1 scn_2 scn_3 scn_4 scn_5 scn_6 using "tables_figures/optim.tex", append f plain   ///
		refcat(\(\qquad\)RRSP "\emph{C. What did people choose?}", nolabel) unstack    ///
		cells("pct(label(Percent) fmt(2))") nomtitles  mlabels(none) collabels(none) varlabels(`e(labels)', blist(Total "")) drop(Total 7 8 ) varwidth(20) nonumber  noobs
		
		
		
		******************************************************
		* Table OA.5: Did respondents make the right choice? *
		*	 		(PERFECT ADJUSMENT RULE)		    	 *
		******************************************************
		
		
		sum rightv1 if intervention==3
		scalar cont_av_v1=r(mean)
		
		* Bulding the regression V1
		probit rightv1  ib(3).intervention, cluster(id) 
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		estadd scalar cont_av_v1=cont_av_v1
		est store xtrightv1_0
		
		xtprobit rightv1  ib(3).intervention, i(id)  re
		scalar r2=e(r2_b)
		margins, predict(pu0) dydx(*) post
		estadd local re "{YES}"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_1
		
		probit rightv1  ib(3).intervention i.scn, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_2
		
		probit rightv1  ib(3).intervention i.scn sigma delta, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_3
		
		probit rightv1  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_4
		
		probit rightv1  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_5
		
		probit rightv1  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv1_6
		
		probit rightv1  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		estadd scalar r2=r2
		est store xtrightv1_7
		
		xtprobit rightv1  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, re
		scalar r2 = e(r2_b)
		margins, predict(pu0) dydx(*) post
		estadd local re "{YES}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		estadd scalar r2=r2
		est store xtrightv1_8
		
		
		esttab xtrightv1_0 xtrightv1_1 xtrightv1_2 xtrightv1_3 xtrightv1_4 xtrightv1_5 xtrightv1_6 xtrightv1_7 xtrightv1_8  using "tables_figures/rightv1_pooled_controls.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)", pattern(1 1 1 1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(re scnFE r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{Random Effects?}"'  `"\\{Scenario FE?}"'   `"\(R^{2}\)"'  `"{Observations}"'    ))  ///
		refcat(1.wid_sep_div "\parbox{5.5cm}{\textbf{Marital Status} \\[2.5pt] (Married ommitted)}"  1.intervention "\parbox{5.5cm}{\textbf{Intervention} \\[2.5pt] (Control omitted)}" 1.educ_some_uni "\parbox{5.5cm}{\textbf{Education} \\[2.5pt] (High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2.5pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) ///
		order(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index  ) ///
		keep(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index  ) ///
		sub(1.province "Province" 1.intervention "Means-testing arm" 2.intervention "Tax arm" _cons "Constant" sigma "\(\sigma\)" delta "\(\beta\)" \_ _  age "Age" c.Age#c.Age "Age\(^2\)" 1.wid_sep_div "Widow, separated or divorce" 1.never_married "Never married" totinc_i_100000 "Annual income (100,000's)" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree or more" ///
		1.finlit_index "1 correct answer" 2.finlit_index "2 correct answers" 3.finlit_index "3 correct answers" 1.ind_rrsp "Has RRSP" 1.ind_tfsa "Has TFSA" ///
		2.scn "Scenario 2" 3.scn "Scenario 3" 4.scn "Scenario 4" 5.scn "Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) 
		
		
		***************************************************
		* Table 5: Did respondents make the right choice? *
		*	 		(Imperfect Adjustment Rule)		 	  *
		***************************************************
		
		sum rightv2 if intervention==3
		scalar cont_av_v2=r(mean)
		
		probit rightv2  ib(3).intervention, cluster(id) 
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "{NO}"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		estadd scalar cont_av_v2=cont_av_v2
		est store xtrightv2_0
		
		xtprobit rightv2  ib(3).intervention, i(id) re
		scalar r2=e(r2_b)
		margins, predict(pu0) dydx(*) post
		estadd local re "YES"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_1
		
		probit rightv2  ib(3).intervention i.scn, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_2
		
		probit rightv2  ib(3).intervention i.scn sigma delta, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_3
		
		probit rightv2  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_4
		
		probit rightv2  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_5
		
		probit rightv2  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{NO}"
		estadd scalar r2=r2
		est store xtrightv2_6
		
		probit rightv2  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id)
		scalar r2=e(r2_p)
		margins, dydx(*) post
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		estadd scalar r2=r2
		est store xtrightv2_7
		
		xtprobit rightv2  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index,  re
		scalar r2 = e(r2_b)
		margins, predict(pu0) dydx(*) post
		estadd local re "YES"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		estadd scalar r2=r2
		est store xtrightv2_8
		
		
		esttab xtrightv2_0 xtrightv2_1 xtrightv2_2 xtrightv2_3 xtrightv2_4 xtrightv2_5 xtrightv2_6 xtrightv2_7 xtrightv2_8  using "tables_figures/rightv2_pooled_controls.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)", pattern(1 1 1 1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(re scnFE r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{Random Effects?}"' `"\\{Scenario FE?}"'  `"\(R^{2}\)"'  `"{Observations}"'    ))  ///
		refcat( 1.wid_sep_div "\parbox{5.5cm}{\textbf{Marital Status} \\[2.5pt] (Married ommitted)}"  1.intervention "\parbox{5.5cm}{\textbf{Intervention} \\[2.5pt] (Control omitted)}" 1.educ_some_uni "\parbox{5.5cm}{\textbf{Education} \\[2.5pt] (High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2.5pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) ///
		order(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index  ) ///
		keep(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index  ) ///
		sub(1.province "Province" 1.intervention "Means-testing arm" 2.intervention "Tax arm" _cons "Constant" sigma "\(\sigma\)" delta "\(\beta\)" \_ _  age "Age" c.Age#c.Age "Age\(^2\)" 1.wid_sep_div "Widow, separated or divorce" 1.never_married "Never married" totinc_i_100000 "Annual income (100,000's)" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree or more" ///
		1.finlit_index "1 correct answer" 2.finlit_index "2 correct answers" 3.finlit_index "3 correct answers" 1.ind_rrsp "Has RRSP" 1.ind_tfsa "Has TFSA" ///
		2.scn "Scenario 2" 3.scn "Scenario 3" 4.scn "Scenario 4" 5.scn "Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) 
		
		
		******************************************************
		* Table OA.4: Did respondents make the right choice? *
		*				(Results by Scenario)				 *		
		******************************************************
		
					
		* Simple logit 1 people chose optimal thing to do, 0 else
		* x indexes the scenarios, y indexes the optimality rule in what follows
		
		foreach x in 1 2 3 4 5 6 {
			foreach y in 1 2  {
				probit rightv`y' ib(3).intervention if scn==`x' 
				scalar r2=e(r2_p)
				margins, dydx(1.intervention 2.intervention) post
				sum rightv`y' if intervention==3 & scn==`x' 
				estadd scalar base=r(mean)
				estadd scalar r2=r2
				est store rightv`y'_`x'
			}	
		}
		
		esttab rightv1_1 rightv1_2 rightv1_3 rightv1_4 rightv1_5 rightv1_6 using "tables_figures/rightchoice_1.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "Scn1" "Scn2" "Scn3" "Scn4" "Scn5" "Scn6" "Score", pattern(1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(base r2 N , fmt(2 3  %12.0fc )  labels(`"\qquad Control avg."' `"\\ \(\qquad R^{2}\)"'  `"{\qquad Observations}"'    ))  ///
		refcat(1.intervention "\emph{A. Perfect adjustment rule}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) sub(\_ _  Constant "\(\qquad\) Constant(None)" "Means-testing arm" "\(\qquad\) Means-testing arm" "Tax arm" "\(\qquad\) Tax arm"  ) ///
		order(1.intervention 2.intervention ) ///
		keep(1.intervention 2.intervention )  ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) label
		
		esttab rightv2_1 rightv2_2 rightv2_3 rightv2_4 rightv2_5 rightv2_6 using "tables_figures/rightchoice_1.tex", append f plain booktabs b(3) p(3)  ///
		stats(base r2 N , fmt(2 3  %12.0fc )  labels(`"\qquad Control avg."' `"\\ \(\qquad R^{2}\)"'  `"{\qquad Observations}"'    ))  ///
		refcat(1.intervention "\emph{B. Imperfect adjustment rule}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) sub(\_ _  Constant "\(\qquad\) Constant(None)" "Means-testing arm" "\(\qquad\) Means-testing arm" "Tax arm" "\(\qquad\) Tax arm"  ) ///
		order(1.intervention 2.intervention ) ///
		keep(1.intervention 2.intervention  )  ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) label
		
		

		***********************************************************
		* FFigure OA.5 (a) and (b): Treatment Effect Distribution *
		***********************************************************
		
		* Knowledge Questions
			
		gen know_score1=(know_score>=0.2) if tag
		gen know_score2=(know_score>=0.4) if tag
		gen know_score3=(know_score>=0.6) if tag
		gen know_score4=(know_score>=0.8) if tag
		gen know_score5=(know_score==1) if tag
		
		*Create a score for choosing the right thing over the 6 scenarios
		foreach x in 1 2  {
				capture drop scene_scorev_`x'				
				egen scene_scorev_`x'=mean(rightv`x'), by(id) 
				
				reg scene_scorev_`x' ib(3).intervention if tag
				sum scene_scorev_`x' if intervention==3 & tag
				estadd scalar base=r(mean)
				est store scene_scorev_`x'
		}	
		
		
		* Workaround to plot the results easily
		capture ssc install coefplot
		
		foreach x in 1 2 3 4 5 {
			capture drop int_recode_`x'
			gen int_recode_`x'=intervention
			reg know_score`x' ib(3).int_recode_`x'
			est store know_meanstest_`x'
		}
		
		foreach x in 1 2 3 4 5 {
			recode int_recode_`x' (1=4) (2=1)
			reg know_score`x' ib(3).int_recode_`x'
			est store know_tax_`x'
			drop int_recode_`x'
		}
		
		coefplot (know_meanstest_1, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0) label("Mean-testing arm")) (know_meanstest_2, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (know_meanstest_3, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (know_meanstest_4, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (know_meanstest_5, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) ///
				 (know_tax_1, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large) label("Tax arm")) (know_tax_2, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (know_tax_3, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (know_tax_4, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (know_tax_5, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)), ///
				keep(1.int_recode_1 1.int_recode_2 1.int_recode_3 1.int_recode_4 1.int_recode_5 ) order(1.int_recode_1 1.int_recode_2 1.int_recode_3 1.int_recode_4 1.int_recode_5 ) ///
				legend(order(2 12)) graphregion(color(white)) bgcolor(white) xlabel(,nogrid) ylabel(,nogrid) grid(none) vertical yline(0,lcolor(black)) ///
				coeflabel (1.int_recode_1 = "0.2" 1.int_recode_2 = "0.4" 1.int_recode_3 = "0.6" 1.int_recode_4 = "0.8" 1.int_recode_5 = "1")
		graph export "tables_figures/know_score_dist.pdf", as(pdf) replace	
		
				
		
					
		* Scenario Choices (v2)
		gen scene_scorev2_1=(scene_scorev_2>=0.2) if tag
		gen scene_scorev2_2=(scene_scorev_2>=0.4) if tag
		gen scene_scorev2_3=(scene_scorev_2>=0.6) if tag
		gen scene_scorev2_4=(scene_scorev_2>=0.8) if tag
		gen scene_scorev2_5=(scene_scorev_2==1) if tag
		
		* Workaround to plot the results easily
		
		foreach x in 1 2 3 4 5 {
			capture drop int_recode_`x'
			gen int_recode_`x'=intervention
			reg scene_scorev2_`x' ib(3).int_recode_`x'
			est store scene_meanstest2_`x'
		}
		
		foreach x in 1 2 3 4 5 {
			recode int_recode_`x' (1=4) (2=1)
			reg scene_scorev2_`x' ib(3).int_recode_`x'
			est store scene_tax2_`x'			
			drop int_recode_`x'
		}
		
		coefplot (scene_meanstest2_1, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0) label("Mean-testing arm")) (scene_meanstest2_2, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (scene_meanstest2_3, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (scene_meanstest2_4, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) (scene_meanstest2_5, ciopts(lcol(gs0)) msymbol(C) mcolor(gs0)) ///
				 (scene_tax2_1, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large) label("Tax arm")) (scene_tax2_2, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (scene_tax2_3, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (scene_tax2_4, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)) (scene_tax2_5, ciopts(lcol(gs0)) msymbol(X) mcolor(gs0) msize(large)), ///
		keep(1.int_recode_1 1.int_recode_2 1.int_recode_3 1.int_recode_4 1.int_recode_5 ) order(1.int_recode_1 1.int_recode_2 1.int_recode_3 1.int_recode_4 1.int_recode_5 ) ///
		legend(order(2 12)) graphregion(color(white)) bgcolor(white) xlabel(,nogrid) ylabel(,nogrid) grid(none) vertical yline(0,lcolor(black)) ///
		coeflabel (1.int_recode_1 = "0.2" 1.int_recode_2 = "0.4" 1.int_recode_3 = "0.6" 1.int_recode_4 = "0.8" 1.int_recode_5 = "1")
		graph export "tables_figures/scene_scoreUtil_dist.pdf", as(pdf) replace
		
		
		
	
		**************************************
		* Table OA.6: Discounted Dollar Loss *
		* 	(PERFECT ADJUSTMENT RULE)	 	 *
		**************************************
		
		* Control average
		sum dollar_mistake if intervention==3
		scalar picont_av_v2=r(mean)
								
		* Get a regression of these welfare losses on observables
		reg dollar_mistake  ib(3).intervention, cluster(id) 
		estadd local re "NO"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"		
		estadd scalar picont_av_v2=picont_av_v2
		est store xtpi_lin_0
		
		xtreg dollar_mistake  ib(3).intervention, i(id) cluster(id) re
		estadd local re "{YES}"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		local r2 = e(r2_b)
		estadd scalar r2 = `r2'
		est store xtpi_lin_1
		
		reg dollar_mistake  ib(3).intervention i.scn, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_lin_2
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_lin_3
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_lin_4
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_lin_5
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{NO}"
		est store xtpi_lin_6
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		est store xtpi_lin_7
		
		xtreg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id) re
		estadd local re "{YES}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		local r2 = e(r2_b)
		estadd scalar r2 = `r2'
		est store xtpi_lin_8
		
		
		esttab xtpi_lin_0 xtpi_lin_1 xtpi_lin_2 xtpi_lin_3 xtpi_lin_4 xtpi_lin_5 xtpi_lin_6 xtpi_lin_7 xtpi_lin_8  using "tables_figures/pi_lin_controls.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)", pattern(1 1 1 1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(re scnFE r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{Random Effects?}"' `"\\{Scenario FE?}"'  `"\(R^{2}\)"'  `"{Observations}"'    ))  ///
		refcat(1.wid_sep_div "\parbox{5.5cm}{\textbf{Marital Status} \\[2.5pt] (Married ommitted)}"  1.intervention "\parbox{5.5cm}{\textbf{Intervention} \\[2.5pt] (Control omitted)}" 1.educ_some_uni "\parbox{5.5cm}{\textbf{Education} \\[2.5pt] (High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2.5pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) ///
		order(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index _cons ) ///
		keep(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index _cons ) ///
		sub(1.intervention "Means-testing arm" 2.intervention "Tax arm" _cons "Constant" sigma "\(\sigma\)" delta "\(\beta\)" \_ _  age "Age" c.Age#c.Age "Age\(^2\)" 1.wid_sep_div "Widow, separated or divorce" 1.never_married "Never married" totinc_i_100000 "Annual income (100,000's)" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree or more" ///
		1.finlit_index "1 correct answer" 2.finlit_index "2 correct answers" 3.finlit_index "3 correct answers" 1.ind_rrsp "Has RRSP" 1.ind_tfsa "Has TFSA" ///
		1.province "Province" 2.scn "Scenario 2" 3.scn "Scenario 3" 4.scn "Scenario 4" 5.scn "Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) 
		
						
		***********************************************
		* Table 6: Discounted Welfare Loss in Dollars *
		* 		(IMPERFECT ADJUSTMENT RULE)			  *
		***********************************************
		
		
		sum pi if intervention==3
		scalar picont_av_v1=r(mean)
		
		* Get a regression of these welfare losses on observables
		reg pi  ib(3).intervention, cluster(id) 
		estadd local re "NO"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		estadd scalar picont_av_v1=picont_av_v1
		est store xtpi_0
		
		xtreg pi  ib(3).intervention, i(id) cluster(id) re
		estadd local re "{YES}"
		estadd local scnFE "{NO}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		local r2 = e(r2_b)
		estadd scalar r2 = `r2'
		est store xtpi_1
		
		reg pi  ib(3).intervention i.scn, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{NO}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_2
		
		reg pi  ib(3).intervention i.scn sigma delta, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_3
		
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_4
		
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{NO}"
		estadd local finlit "{NO}"
		est store xtpi_5
		
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{NO}"
		est store xtpi_6
		
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id)
		estadd local re "NO"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		est store xtpi_7
		
		xtreg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id) re
		estadd local re "{YES}"
		estadd local scnFE "{YES}"
		estadd local prefs "{YES}"
		estadd local demogs "{YES}"
		estadd local finlit "{YES}"
		local r2 = e(r2_b)
		estadd scalar r2 = `r2'
		est store xtpi_8
		
		
			
		esttab xtpi_0 xtpi_1 xtpi_2 xtpi_3 xtpi_4 xtpi_5 xtpi_6 xtpi_7 xtpi_8  using "tables_figures/pi_pooled_controls.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)", pattern(1 1 1 1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		stats(re scnFE r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{Random Effetcs?}"' `"\\{Scenario FE?}"'  `"\(R^{2}\)"'  `"{Observations}"'    ))  ///
		refcat( 1.wid_sep_div "\parbox{5.5cm}{\textbf{Marital Status} \\[2.5pt] (Married ommitted)}"  1.intervention "\parbox{5.5cm}{\textbf{Intervention} \\[2.5pt] (Control omitted)}" 1.educ_some_uni "\parbox{5.5cm}{\textbf{Education} \\[2.5pt] (High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2.5pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) ///
		order(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index _cons ) ///
		keep(1.intervention 2.intervention sigma delta 1.ind_rrsp 1.ind_tfsa age c.age#c.age 1.wid_sep_div 1.never_married totinc_i_100000 1.province 1.educ_some_uni 1.educ_bach_more 1.finlit_index 2.finlit_index 3.finlit_index _cons ) ///
		sub(1.intervention "Means-testing arm" 2.intervention "Tax arm" _cons "Constant" sigma "\(\sigma\)" delta "\(\beta\)" \_ _  age "Age" c.Age#c.Age "Age\(^2\)" 1.wid_sep_div "Widow, separated or divorce" 1.never_married "Never married" totinc_i_100000 "Annual income (100,000's)" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree or more" ///
		1.finlit_index "1 correct answer" 2.finlit_index "2 correct answers" 3.finlit_index "3 correct answers" 1.ind_rrsp "Has RRSP" 1.ind_tfsa "Has TFSA" ///
		1.province "Province" 2.scn "Scenario 2" 3.scn "Scenario 3" 4.scn "Scenario 4" 5.scn "Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) 
		
		
		
		*********************************************************************
		* TABLE OA.8: Loss Based on the Optimal Vehicle and Adjustment Rule *
		*********************************************************************
		
		
		* PERFECT ADJUSTMENT RULE
		* RRSP
		reg dollar_mistake  ib(3).intervention if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store RRSPpi_lin_0
		
		xtreg dollar_mistake  ib(3).intervention   if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "NO"
		est store RRSPpi_lin_1
		
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store RRSPpi_lin_2
		
		xtreg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store RRSPpi_lin_3
		
		
		* TFSA
		reg dollar_mistake  ib(3).intervention if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store TFSApi_lin_0
		
		xtreg dollar_mistake  ib(3).intervention if optimv2==1 , re 
		estadd local re "YES"
		estadd local cont "NO"
		est store TFSApi_lin_1
	
		reg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store TFSApi_lin_2
		
		xtreg dollar_mistake  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store TFSApi_lin_3
		
		
		* IMPERFECT ADJUSTMENT RULE
		* RRSP
		reg pi  ib(3).intervention if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store RRSPpi_0
		
		xtreg pi  ib(3).intervention   if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "NO"
		est store RRSPpi_1
		
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store RRSPpi_2
		
		xtreg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store RRSPpi_3
		
		
		* TFSA
		reg pi  ib(3).intervention if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store TFSApi_0
		
		xtreg pi  ib(3).intervention if optimv2==1 , re 
		estadd local re "YES"
		estadd local cont "NO"
		est store TFSApi_1
	
		reg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store TFSApi_2
		
		xtreg pi  ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store TFSApi_3
		
		
		esttab  RRSPpi_0 RRSPpi_1 RRSPpi_2 RRSPpi_3 TFSApi_0 TFSApi_1 TFSApi_2 TFSApi_3  using "tables_figures/pi_cond.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups("RRSP Optimal" "TFSA Optimal" , pattern(1 0 0 0 1 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		mtitle ("(1)" "(2)"  "(3)" "(4)" "(5)" "(6)" "(7)" "(8)") star(* 0.10 ** 0.05 *** 0.01) /// 
		stats(re cont r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{\(\qquad\)Random Effects?}"' `"{\(\qquad\)Controls?}"'   `"\(\qquad\)\(R^{2}\)"'  `"{\(\qquad\)Observations}"'    ))  ///
		refcat( 1.intervention "\parbox{5.5cm}{\textit{A. Discounted Welfare Loss} \\[2.5pt] \hspace*{7mm} \textbf{Intervention} \\[2.5pt] \hspace*{7mm}(Control omitted)}"  2.scn "\parbox{5.5cm}{\(\qquad\)\textbf{Scenario Fixed Effects} \\[2.5pt] \(\qquad\)(Scenario 1 ommitted)}" 1.wid_sep_div "\parbox{5.5cm}{\(\qquad\)\textbf{Marital Status} \\[2.5pt] \(\qquad\)(Married ommitted)}" 1.educ_some_uni "\parbox{5.5cm}{\(\qquad\)\textbf{Education} \\[2.5pt] \(\qquad\)(High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\(\qquad\)\textbf{Financial Literacy} \\[2.5pt] \(\qquad\)(0 Right answer ommitted)}", nolabel) unstack  ///
		collabels(none) ///
		order(1.intervention 2.intervention _cons) /// 
		keep(1.intervention 2.intervention _cons ) ///
		sub(1.intervention "\(\qquad\)Means-testing arm" 2.intervention "\(\qquad\)Tax arm" _cons "\(\qquad\)Constant" sigma "\(\qquad\)\(\sigma\)" delta "\(\qquad\)\(\beta\)" \_ _  age "\(\qquad\)Age" c.Age#c.Age "\(\qquad\)Age\(^2\)" 1.wid_sep_div "\(\qquad\)Widow, separated or divorce" 1.never_married "\(\qquad\)Never married" totinc_i_100000 "\(\qquad\)Annual income (100,000's)" 1.educ_some_uni "\(\qquad\)Some university" 1.educ_bach_more "\(\qquad\)Bachelor degree or more" ///
		1.finlit_index "\(\qquad\)1 correct answer" 2.finlit_index "\(\qquad\)2 correct answers" 3.finlit_index "\(\qquad\)3 correct answers" 1.ind_rrsp "\(\qquad\)Has RRSP" 1.ind_tfsa "\(\qquad\)Has TFSA" ///
		1.province "\(\qquad\)Province" 2.scn "\(\qquad\)Scenario 2" 3.scn "\(\qquad\)Scenario 3" 4.scn "\(\qquad\)Scenario 4" 5.scn "\(\qquad\)Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) 
		
		
		esttab  RRSPpi_lin_0 RRSPpi_lin_1 RRSPpi_lin_2 RRSPpi_lin_3 TFSApi_lin_0 TFSApi_lin_1 TFSApi_lin_2 TFSApi_lin_3 using "tables_figures/pi_cond.tex", append f plain booktabs b(3) p(3)  ///
		nomtitle stats(re cont r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{\(\qquad\)Random Effects?}"' `"{\(\qquad\)Controls?}"'   `"\(\qquad\)\(R^{2}\)"'  `"{\(\qquad\)Observations}"'    ))  ///
		refcat( 1.intervention "\parbox{5.5cm}{\textit{B. Discounted Dollar Loss} \\[2.5pt] \hspace*{7mm} \textbf{Intervention} \\[2.5pt] \hspace*{7mm}(Control omitted)}"  2.scn "\parbox{5.5cm}{\(\qquad\)\textbf{Scenario Fixed Effects} \\[2.5pt] \(\qquad\)(Scenario 1 ommitted)}" 1.wid_sep_div "\parbox{5.5cm}{\(\qquad\)\textbf{Marital Status} \\[2.5pt] \(\qquad\)(Married ommitted)}" 1.educ_some_uni "\parbox{5.5cm}{\(\qquad\)\textbf{Education} \\[2.5pt] \(\qquad\)(High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\(\qquad\)\textbf{Financial Literacy} \\[2.5pt] \(\qquad\)(0 Right answer ommitted)}", nolabel) unstack  ///
		collabels(none) ///
		order(1.intervention 2.intervention _cons) /// 
		keep(1.intervention 2.intervention _cons ) ///
		sub(1.intervention "\(\qquad\)Means-testing arm" 2.intervention "\(\qquad\)Tax arm" _cons "\(\qquad\)Constant" sigma "\(\qquad\)\(\sigma\)" delta "\(\qquad\)\(\beta\)" \_ _  age "\(\qquad\)Age" c.Age#c.Age "\(\qquad\)Age\(^2\)" 1.wid_sep_div "\(\qquad\)Widow, separated or divorce" 1.never_married "\(\qquad\)Never married" totinc_i_100000 "\(\qquad\)Annual income (100,000's)" 1.educ_some_uni "\(\qquad\)Some university" 1.educ_bach_more "\(\qquad\)Bachelor degree or more" ///
		1.finlit_index "\(\qquad\)1 correct answer" 2.finlit_index "\(\qquad\)2 correct answers" 3.finlit_index "\(\qquad\)3 correct answers" 1.ind_rrsp "\(\qquad\)Has RRSP" 1.ind_tfsa "\(\qquad\)Has TFSA" ///
		1.province "\(\qquad\)Province" 2.scn "\(\qquad\)Scenario 2" 3.scn "\(\qquad\)Scenario 3" 4.scn "\(\qquad\)Scenario 4" 5.scn "\(\qquad\)Scenario 5" 6.scn "Scenario 6" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) 
		
			
		**************************************
		* Table OA.7: Heterogeneous Effects. *
		**************************************
	
				
		********************************
		* Heterogeneous Fx : education *
		********************************
		
		* Knowledge Score + Educ
		reg know_score ib(3).intervention##i.educ_some_uni b(3).intervention#i.educ_bach_more i.educ_bach_more  if tag
		
		test 1.intervention#1.educ_bach_more 1.intervention#1.educ_some_uni
		estadd local refcat ""
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.educ_bach_more 2.intervention#1.educ_some_uni
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store kscore_educ
		
		* Dollar Loss + Educ
		reg dollar_mistake ib(3).intervention##i.educ_some_uni b(3).intervention#i.educ_bach_more i.educ_bach_more  if tag
		
		test 1.intervention#1.educ_bach_more 1.intervention#1.educ_some_uni
		estadd local refcat ""
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.educ_bach_more 2.intervention#1.educ_some_uni
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store dollar_mistake_educ
		
		* Welfare Loss + Educ
		reg pi ib(3).intervention##i.educ_some_uni b(3).intervention#i.educ_bach_more i.educ_bach_more  if tag
		
		test 1.intervention#1.educ_bach_more 1.intervention#1.educ_some_uni
		estadd local refcat ""
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.educ_bach_more 2.intervention#1.educ_some_uni
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store pi_educ
		
		************************************
		* Heterogeneous FX : Financial lit *
		************************************
		
		
		* Knowledge Score + Educ
		reg know_score ib(3).intervention##i.finlit1 ib(3).intervention#i.finlit2 ib(3).intervention#i.finlit3 i.finlit1 i.finlit2 i.finlit3  if tag
		
		test 1.intervention#1.finlit1 1.intervention#1.finlit2 1.intervention#1.finlit3
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.finlit1 2.intervention#1.finlit2 2.intervention#1.finlit3
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store kscore_finlit
		
		* Scenario Score 1 + Educ
		reg dollar_mistake ib(3).intervention##i.finlit1 ib(3).intervention#i.finlit2 ib(3).intervention#i.finlit3 i.finlit1 i.finlit2 i.finlit3  if tag
		
		test 1.intervention#1.finlit1 1.intervention#1.finlit2 1.intervention#1.finlit3
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.finlit1 2.intervention#1.finlit2 2.intervention#1.finlit3
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store dollar_mistake_finlit
		
		* Scenario Score 2 + Educ
		reg pi	ib(3).intervention##i.finlit1 ib(3).intervention#i.finlit2 ib(3).intervention#i.finlit3 i.finlit1 i.finlit2 i.finlit3  if tag
		
		test 1.intervention#1.finlit1 1.intervention#1.finlit2 1.intervention#1.finlit3
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.finlit1 2.intervention#1.finlit2 2.intervention#1.finlit3
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store pi_finlit
		
		
		*****************************
		* Heterogeneous FX : Gender *
		*****************************
		
				
		* Knowledge Score + Gender
		reg know_score ib(3).intervention##ib(0).male 1.male if tag
		
		test 1.intervention#1.male
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.male
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store kscore_male
		
		* Scenario Score 1 + Gender
		reg dollar_mistake ib(3).intervention##ib(0).male  1.male  if tag
		
		test 1.intervention#1.male
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.male
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store dollar_mistake_male
		
		* Scenario Score 2 + Gender
		reg pi	ib(3).intervention##ib(0).male  1.male  if tag
		
		test 1.intervention#1.male
		estadd scalar ftest1=r(F)
		estadd scalar pval1=r(p)
		test 2.intervention#1.male
		estadd scalar ftest2=r(F)
		estadd scalar pval2=r(p)
		
		est store pi_male
		
		
		* Export
		esttab kscore_educ dollar_mistake_educ pi_educ using "tables_figures/heterofx.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups( "Knowledge" "\parbox{2cm}{Discounted \\[2pt] Dollar Loss}" "\parbox{2.2cm}{Discounted \\[2pt] Welfare Loss}" , pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		refcat(1.intervention#1.educ_some_uni   "\parbox{5.5cm}{\textbf{Education} \\[2pt] (High School or less omitted)}" , nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) stats(r2 , fmt(3   )  labels(`" \(R^{2}\)"'  )) ///
		order(1.intervention#1.educ_some_uni 1.intervention#1.educ_bach_more 2.intervention#1.educ_some_uni 2.intervention#1.educ_bach_more) ///
		keep(1.intervention#1.educ_some_uni 1.intervention#1.educ_bach_more 2.intervention#1.educ_some_uni 2.intervention#1.educ_bach_more) ///
		sub(\_ _  1.intervention "Means-testing arm" 2.intervention "Tax arm" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree+" ///
		 "#" "\(\times\)" _cons "Constant") ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) noobs
		
		esttab kscore_finlit dollar_mistake_finlit pi_finlit using "tables_figures/heterofx.tex", append f plain booktabs b(3) p(3)  ///
		refcat(1.intervention#1.finlit1 "\parbox{5.5cm}{\textbf{Financial Literacy} \\[2pt] (0 Right answer ommitted)}", nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) stats(r2 , fmt(3   )  labels(`" \(R^{2}\)"'  )) ///
		order(1.intervention#1.finlit1 1.intervention#1.finlit2 1.intervention#1.finlit3 2.intervention#1.finlit1 2.intervention#1.finlit2 2.intervention#1.finlit3) ///
		keep(1.intervention#1.finlit1 1.intervention#1.finlit2 1.intervention#1.finlit3 2.intervention#1.finlit1 2.intervention#1.finlit2 2.intervention#1.finlit3) ///
		sub(\_ _  1.intervention "Means-testing arm" 2.intervention "Tax arm" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree+" ///
		 "#" "\(\times\)"  1.finlit1 "1 correct answer" 1.finlit2 "2 correct answers" 1.finlit3 "3 correct answers" _cons "Constant") ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) noobs
	
		esttab kscore_male dollar_mistake_male pi_male using "tables_figures/heterofx.tex", append f plain booktabs b(3) p(3)  ///
		refcat(1.intervention#1.male "\parbox{5.5cm}{\textbf{Gender} \\[2pt] (Female omitted)}" , nolabel) unstack  ///
		star(* 0.10 ** 0.05 *** 0.01)   ///
		collabels(none) stats(r2 , fmt(3   )  labels(`"\(R^{2}\)"'  ))  ///
		order(1.intervention#1.male 2.intervention#1.male) ///
		keep(1.intervention#1.male 2.intervention#1.male) ///
		sub(\_ _  1.intervention "Means-testing arm" 2.intervention "Tax arm" 1.male "Male" ///
		 "#" "\(\times\)"  _cons "Constant" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum nomtitles nogaps eqlabels(none) noobs
		
		
		
		
		*******************************
		* Table OA.1: Factor Analysis *
		*******************************
		
		* Need to do a special factor analysis for dummy variables: polychoric correlation
		* Note that it is almost exactly the same as a normal/continuous factor analysis: factor q37 q38 q39 q40 q41 if tag
		
		capture net describe polychoric, from(http://staskolenikov.net/stata)
		
		polychoric q37 q38 q39 q40 q41 if tag
		global N = r(sum_w)

		matrix r = r(R)
		factormat r, n($N) factors(3)
		est store factor
		
		esttab factor  using "tables_figures/factor.tex", replace f plain booktabs b(3) p(3) ///
		cells("L[Factor1](t) L[Factor2](t) Psi[Uniqueness]") ///
		nogap noobs nonumber nomtitle sub( q37 "Q1" q38 "Q2" q39 "Q3" q40 "Q4" q41 "Q5")
		
		esttab e(Ev) using "tables_figures/factor.tex", append f plain booktabs b(3) p(3) ///
		nogap noobs nonumber nomtitle 
		 
		
			
		******************************************
		* Table OA.11: Joint Mediation Analysis. *
		******************************************
		
		* For this section let's re-create a variable called: 
		* treat that takes 0 for control, 1 for tax and 2 for means-testing
		
		gen treat=intervention
		recode treat (3=0) 
		
		* The medeff command does not accept factor variables
		gen age2=age*age
		
		* Full set of covariates
		global covariates sigma delta age age2 ind_rrsp ind_tfsa wid_sep_div never_married totinc_i_100000 educ_some_uni educ_bach_more province finlit1 finlit2 finlit3
		
		
		****************************************************************************
		* FIRST WAY: Combining all mediators in a single joint system of equations *
		****************************************************************************
				
		* Full set of covariates
		global covariates sigma delta age age2 ind_rrsp ind_tfsa wid_sep_div never_married totinc_i_100000 educ_some_uni educ_bach_more province finlit1 finlit2 finlit3
		
		* Mediation combining all questions
		
		capture program drop medqs
		program medqs, rclass
		
			args m1 m2 m3 m4 m5 y
			confirm var `m1'
			confirm var `m2'
			confirm var `m3'
			confirm var `m4'
			confirm var `m5'
			confirm var `y'
		
		sureg 	(`m1' treat $covariates) (`m2' treat $covariates) (`m3' treat $covariates) (`m4' treat $covariates) (`m5' treat $covariates) ///
				(`y' `m1' `m2' `m3' `m4' `m5' treat $covariates)
			
			return scalar beta1_1    = ([`m1']_b[treat]) 
			return scalar beta1_2    = ([`m2']_b[treat]) 
			return scalar beta1_3    = ([`m3']_b[treat]) 
			return scalar beta1_4    = ([`m4']_b[treat]) 
			return scalar beta1_5    = ([`m5']_b[treat]) 
			
			return scalar alpha1   	 = [`y']_b[treat]
			
			return scalar alpha2_1   = [`y']_b[`m1']
			return scalar alpha2_2   = [`y']_b[`m2']
			return scalar alpha2_3   = [`y']_b[`m3']
			return scalar alpha2_4   = [`y']_b[`m4']
			return scalar alpha2_5   = [`y']_b[`m5']
			
			return scalar indirect_1 = [`m1']_b[treat]*[`y']_b[`m1']
			return scalar total_1	 = [`y']_b[treat]+[`m1']_b[treat]*[`y']_b[`m1']
			
			return scalar indirect_2 = [`m2']_b[treat]*[`y']_b[`m2']
			return scalar total_2    = [`y']_b[treat]+[`m2']_b[treat]*[`y']_b[`m2']
			
			return scalar indirect_3 = [`m3']_b[treat]*[`y']_b[`m3']
			return scalar total_3    = [`y']_b[treat]+[`m3']_b[treat]*[`y']_b[`m3']
			
			return scalar indirect_4 = [`m4']_b[treat]*[`y']_b[`m4']
			return scalar total_4	 = [`y']_b[treat]+[`m4']_b[treat]*[`y']_b[`m4']
			
			return scalar indirect_5 = [`m5']_b[treat]*[`y']_b[`m5']
			return scalar total_5	 = [`y']_b[treat]+[`m5']_b[treat]*[`y']_b[`m5']
		
		end
		
		foreach y in dollar_mistake pi {
		
			bootstrap 	alpha2_1=r(alpha2_1) alpha2_2=r(alpha2_2) alpha2_3=r(alpha2_3) alpha2_4=r(alpha2_4) alpha2_5=r(alpha2_5) ///
						indirect_1=r(indirect_1) indirect_2=r(indirect_2) indirect_3=r(indirect_3) indirect_4=r(indirect_4) indirect_5=r(indirect_5) ///
						total_1=r(total_1) total_2=r(total_2) total_3=r(total_3) total_4=r(total_4) total_5=r(total_5), ///
						reps(1000) nodots: medqs q37 q38 q39 q40 q41 `y'
			est store `y'_all
		
			* Calculate the percentage mediated, and get standard errors using the delta method.
			nlcom 	(pctmed_1:_b[indirect_1] / _b[total_1]) ///
					(pctmed_2:_b[indirect_2] / _b[total_2]) ///
					(pctmed_3:_b[indirect_3] / _b[total_3]) /// 
					(pctmed_4:_b[indirect_4] / _b[total_4]) /// 
					(pctmed_5:_b[indirect_5] / _b[total_5]) , post
			
			estadd local cont "YES"
			est store b`y'_all
				
		}
		
		
		
		************************************************
		* Second Way: Doing it for the knowlege score. *
		************************************************
		
		* Set up a program that takes M and Y and calculates the quantities of interest
		capture program drop  mediation
		program mediation, rclass
		
			args m y
			confirm var `m'
			confirm var `y'
			
			sureg (`m' treat $covariates)(`y' `m' treat $covariates)
			return scalar beta1    = ([`m']_b[treat]) 
			return scalar alpha1   = [`y']_b[treat]
			return scalar alpha2   = [`y']_b[`m']
			return scalar indirect = [`m']_b[treat]*[`y']_b[`m']
			return scalar total	   = [`y']_b[treat]+[`m']_b[treat]*[`y']_b[`m']
			
		end
		
		* For each of our Mediators and Outcome variables, bootstrap the standard errors
		foreach y in dollar_mistake pi {
			foreach m in know_score q37 q38 q39 q40 q41  {
			
				bootstrap beta1=r(beta1) alpha1=r(alpha1) alpha2=r(alpha2) indirect=r(indirect) total=r(total) , reps(1000) nodots: mediation `m' `y'
				est store `y'_`m'
				
				* Calculate the percentage mediated, and get standard errors using the delta method.
				nlcom pctmed:_b[indirect] / _b[total], post
				
				estadd local cont "YES"
				est store b`y'_`m'
				
			}
		}
		
	
		* EXPORT 
	
		esttab dollar_mistake_all pi_all dollar_mistake_know_score pi_know_score using "tables_figures/med_hand.csv", replace  f plain b(3) p(3) ///
		star(* 0.10 ** 0.05 *** 0.01)  ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) nomtitles collabels(none) noobs
		
		esttab bdollar_mistake_all bpi_all bdollar_mistake_know_score bpi_know_score using "tables_figures/med_hand.csv", append  f plain b(3) p(3) ///
		stats(cont N  , fmt(0 %12.0fc) labels(`"{\(\qquad\)Controls?}"' `"{\(\qquad\)Observations}"' )) star(* 0.10 ** 0.05 *** 0.01)   ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) nomtitles collabels(none) 
		
		
		
		
		
		*********************************************************
		* Table OA.12: Mediation Analysis (Imai et. al version) *
		*********************************************************
		
		capture ssc install mediation
		
		global covariates sigma delta age age2 ind_rrsp ind_tfsa wid_sep_div never_married totinc_i_100000 educ_some_uni educ_bach_more province finlit1 finlit2 finlit3
		
		* Let's do it for the total score, and for each question separately AND for $ loss and welfare loss.
		
		* Do it for Dollar mistake and for pi / Mediator is knowledge score
		foreach y in dollar_mistake pi {		
			medeff (regress know_score treat $covariates) (regress `y' treat know_score $covariates), treat(treat 1 2) mediate(know_score) sims(1000)
			matrix coeffs= (r(delta1), r(zeta1), r(tau), r(navg))
			matrix cilo=(r(delta1lo), r(zeta1lo), r(taulo), r(navglo))
			matrix cihi=(r(delta1hi), r(zeta1hi), r(tauhi), r(navghi))
			
			estadd matrix coeffs = coeffs
			estadd matrix cilo=cilo
			estadd matrix cihi=cihi
			estadd local cont "YES"
			
			est store `y'_score
		}
		
		* Now do it by question -- probit for the right answer on the q
		foreach y in dollar_mistake pi {
			foreach m in q37 q38 q39 q40 q41 {
				medeff (probit `m' treat $covariates) (regress `y' treat `m' $covariates), treat(treat 1 2) mediate(`m') sims(1000)
				matrix coeffs= (r(delta1), r(zeta1), r(tau), r(navg))
				matrix cilo=(r(delta1lo), r(zeta1lo), r(taulo), r(navglo))
				matrix cihi=(r(delta1hi), r(zeta1hi), r(tauhi), r(navghi))
				
				estadd matrix coeffs = coeffs
				estadd matrix cilo=cilo
				estadd matrix cihi=cihi
				estadd local cont "YES"
				
				est store `y'_`m'
			}
		}	
		
		* Extremely weird scheme to export results that look OK (put some l and r and then sub them for parentheses...)
		esttab dollar_mistake_score dollar_mistake_q37 dollar_mistake_q38 dollar_mistake_q39 dollar_mistake_q40 dollar_mistake_q41 using "tables_figures/med.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups("Avg. Score" "Q1" "Q2" "Q3" "Q4" "Q5" , pattern(1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		refcat(c1 "A. Discounted Dollar Mistake", nolabel) ///
		stats(cont N  , fmt(0 %12.0fc) labels(`"{\(\qquad\)Controls?}"' `"{\(\qquad\)Observations}"' ))  ///
		sub(c1 "\(\qquad\)ACME" c2 "\(\qquad\)Direct Effect" c3 "\(\qquad\)Total Effect" c4 "\(\qquad\)Pct. Mediated" ///
		"&l" "&(" "r," "," ",l" "," "r&" ")&" "r\\" ")\\") ///
		cells ("coeffs (fmt(%8.2f))" "cilo(fmt(%8.2f)par(l r)) & cihi(fmt(%8.2f)par(l r )) ") incelldelimiter(,)  nonum  nogaps eqlabels(none) nomtitles collabels(none) 
		
		esttab pi_score pi_q37 pi_q38 pi_q39 pi_q40 pi_q41 using "tables_figures/med.tex", append  f plain    ///
		refcat(c1 "B. Discounted Welfare Loss", nolabel) ///
		stats(cont N  , fmt(0 %12.0fc) labels(`"{\(\qquad\)Controls?}"' `"{\(\qquad\)Observations}"' ))   ///
		sub(c1 "\(\qquad\)ACME" c2 "\(\qquad\)Direct Effect" c3 "\(\qquad\)Total Effect" c4 "\(\qquad\)Pct. Mediated" ///
		"&l" "&(" "r," "," ",l" "," "r&" ")&" "r\\" ")\\") ///
		cells ("coeffs (fmt(%8.2f))" "cilo(fmt(%8.2f)par(l r)) & cihi(fmt(%8.2f)par(l r )) ") incelldelimiter(,)  nonum  nogaps eqlabels(none) nomtitles collabels(none) 
		
		 
		 
		 
		*********************************************************************
		* Table OA.10: Welfare Analysis: Instrumental Variables Estimation. *
		*********************************************************************
		
		* Here we instrument the intervention using the score
	
		* Ref Form RE
		xtreg dollar_mistake ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id) re
		estadd local re "YES"
		estadd local cont "YES"
		est store red_dollar
		
		xtreg pi ib(3).intervention i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id) re
		estadd local re "YES"
		estadd local cont "YES"
		est store red_pi
				
		
		* IV RE
		xtivreg dollar_mistake (know_score=ib(3).intervention) i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, re first
		estadd local re "YES"
		estadd local cont "YES"
		est store iv_dollar
		
			* First Stage 
			* On the same sample to be exact
			reg know_score ib(3).intervention scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, cluster(id)
			estadd scalar fstat=e(F)
			estadd local re "YES"
			estadd local cont "YES"
			est store first_stage
			
		xtivreg pi (know_score=ib(3).intervention) i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index, re
		estadd local re "YES"
		estadd local cont "YES"
		est store iv_pi
		
		
		esttab  first_stage red_dollar iv_dollar red_pi iv_pi using "tables_figures/iv_welfare.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups("Knowledge Score" "Discounted Dollar Loss" "Discounted Welfare Loss" , pattern(1 1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		mtitle ("First-Stage" "Reduced Form"  "IV" "Reduced Form" "IV") star(* 0.10 ** 0.05 *** 0.01) /// 
		stats(fstat re cont  N , fmt(%12.2fc 0 0 %12.0fc)  labels( `"\\{F-Stat}"' `"{Random Effects?}"'  `"{Controls?}"'      `"{Observations}"'    ))  ///
		collabels(none) ///
		order(know_score 1.intervention 2.intervention _cons) /// 
		keep(know_score 1.intervention 2.intervention _cons ) ///
		sub(know_score "Knowledge Score" 1.intervention "Means-testing arm" 2.intervention "Tax arm" _cons "Constant" sigma "\(\sigma\)" delta "\(\beta\)" \_ _   ) ///
		cells("b(fmt(%12.2fc)star)" "se(fmt(%12.2fc)par)" ) nonum  nogaps eqlabels(none) 

		
		****************************************************************
		* Table OA.9: Switching Conditional on Current Asset Location. *
		****************************************************************
		
		* Gen the proportion of your total savings in RRSP
		
		gen rrsp_amnt=.
		replace rrsp_amnt= ind_rrsp_amt_i if ind_rrsp==1
		replace rrsp_amnt= 0 if ind_rrsp==0
						
		gen tfsa_amnt=.
		replace tfsa_amnt= ind_tfsa_amt_i if ind_tfsa==1
		replace tfsa_amnt= 0 if ind_tfsa==0
		
		gen rrsp_savings=rrsp_amnt/(rrsp_amnt+tfsa_amnt)
		
		* 0= none or both, 1= mostly rrsp, 2=mostly tfsa
		generate tfsa_cat = rrsp_savings
		recode   tfsa_cat (0/0.25=2) (0.25/0.75=0) (0.75/1=1)
		replace tfsa_cat=0 if tfsa_cat==.
		
		* RRSP
		reg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store RRSPpi_lin_0
		
		xtreg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat   if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "NO"
		est store RRSPpi_lin_1
		
		reg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store RRSPpi_lin_2
		
		xtreg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store RRSPpi_lin_3
		
		
		* TFSA
		reg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store TFSApi_lin_0
		
		xtreg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat if optimv2==1 , re 
		estadd local re "YES"
		estadd local cont "NO"
		est store TFSApi_lin_1
	
		reg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store TFSApi_lin_2
		
		xtreg dollar_mistake  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store TFSApi_lin_3
		
		
		* IMPERFECT ADJUSTMENT RULE
		* RRSP
		reg pi  ib(3).intervention##ib(0).tfsa_cat if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store RRSPpi_0
		
		xtreg pi  ib(3).intervention##ib(0).tfsa_cat   if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "NO"
		est store RRSPpi_1
		
		reg pi  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store RRSPpi_2
		
		xtreg pi  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==0 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store RRSPpi_3
		
		
		* TFSA
		reg pi  ib(3).intervention##ib(0).tfsa_cat if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "NO"
		est store TFSApi_0
		
		xtreg pi  ib(3).intervention##ib(0).tfsa_cat if optimv2==1 , re 
		estadd local re "YES"
		estadd local cont "NO"
		est store TFSApi_1
	
		reg pi  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , cluster(id) 
		estadd local re "NO"
		estadd local cont "YES"
		est store TFSApi_2
		
		xtreg pi  ib(3).intervention##ib(0).tfsa_cat i.scn sigma delta c.age##c.age i.ind_rrsp i.ind_tfsa i.wid_sep_div i.never_married totinc_i_100000 i.province i.educ_some_uni i.educ_bach_more i.finlit_index if optimv2==1 , re
		estadd local re "YES"
		estadd local cont "YES"
		est store TFSApi_3
			
		label define tfsa_catl 1 "\(\qquad\)Mostly RRSP" 2 "\(\qquad\)Mostly TFSA" 0 "\(\qquad\)Both RRSP/TFSA" , modify
		label values tfsa_cat tfsa_catl  

		* Small table
		esttab  RRSPpi_0 RRSPpi_1 RRSPpi_2 RRSPpi_3 TFSApi_0 TFSApi_1 TFSApi_2 TFSApi_3  using "tables_figures/switch_rrsp_tfsa.tex", replace f plain booktabs b(3) p(3)  ///
		mgroups("RRSP Optimal" "TFSA Optimal" , pattern(1 0 0 0 1 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		mtitle ("(1)" "(2)"  "(3)" "(4)" "(5)" "(6)" "(7)" "(8)") star(* 0.10 ** 0.05 *** 0.01) /// 
		stats(re cont r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{\(\qquad\)Random Effects?}"' `"{\(\qquad\)Controls?}"'   `"\(\qquad\)\(R^{2}\)"'  `"{\(\qquad\)Observations}"'    ))  ///
		refcat(1.intervention#1.tfsa_cat "\textit{A. Discounted Welfare Loss}"   2.scn "\parbox{5.5cm}{\(\qquad\)\textbf{Scenario Fixed Effects} \\[2.5pt] \(\qquad\)(Scenario 1 ommitted)}" 1.wid_sep_div "\parbox{5.5cm}{\(\qquad\)\textbf{Marital Status} \\[2.5pt] \(\qquad\)(Married ommitted)}" 1.educ_some_uni "\parbox{5.5cm}{\(\qquad\)\textbf{Education} \\[2.5pt] \(\qquad\)(High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\(\qquad\)\textbf{Financial Literacy} \\[2.5pt] \(\qquad\)(0 Right answer ommitted)}", nolabel) unstack  ///
		collabels(none) label ///
		order(1.intervention#1.tfsa_cat 1.intervention#2.tfsa_cat 2.intervention#1.tfsa_cat 2.intervention#2.tfsa_cat) ///
		keep(1.intervention#1.tfsa_cat 1.intervention#2.tfsa_cat 2.intervention#1.tfsa_cat 2.intervention#2.tfsa_cat) ///
		sub(\_ _   "Means-testing arm $\times$ \(\qquad\)Mostly TFSA" "Means-testing arm $\times$ Mostly TFSA" ///
		"Means-testing arm $\times$ \(\qquad\)Mostly RRSP" "Means-testing arm $\times$ Mostly RRSP" ///
		"Tax arm $\times$ \(\qquad\)Mostly TFSA" "Tax arm $\times$ Mostly TFSA" ///
		"Tax arm $\times$ \(\qquad\)Mostly RRSP" "Tax arm $\times$ Mostly RRSP" ///
		"Means-testing arm" "\(\qquad\)Means-testing arm" "Tax arm" "\(\qquad\)Tax arm" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree+" ///
		"#" "\(\times\)"  Constant "\(\qquad\)Constant" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) 
		
		
		esttab  RRSPpi_lin_0 RRSPpi_lin_1 RRSPpi_lin_2 RRSPpi_lin_3 TFSApi_lin_0 TFSApi_lin_1 TFSApi_lin_2 TFSApi_lin_3 using "tables_figures/switch_rrsp_tfsa.tex", append f plain booktabs b(3) p(3)  ///
		nomtitle stats(re cont r2 N , fmt(0 0 3  %12.0fc)  labels( `"\\{\(\qquad\)Random Effects?}"' `"{\(\qquad\)Controls?}"'   `"\(\qquad\)\(R^{2}\)"'  `"{\(\qquad\)Observations}"'    ))  ///
		refcat(1.intervention#1.tfsa_cat "\textit{B. Discounted Dollar Loss}"   2.scn "\parbox{5.5cm}{\(\qquad\)\textbf{Scenario Fixed Effects} \\[2.5pt] \(\qquad\)(Scenario 1 ommitted)}" 1.wid_sep_div "\parbox{5.5cm}{\(\qquad\)\textbf{Marital Status} \\[2.5pt] \(\qquad\)(Married ommitted)}" 1.educ_some_uni "\parbox{5.5cm}{\(\qquad\)\textbf{Education} \\[2.5pt] \(\qquad\)(High School or less omitted)}"  1.finlit_index "\parbox{5.5cm}{\(\qquad\)\textbf{Financial Literacy} \\[2.5pt] \(\qquad\)(0 Right answer ommitted)}", nolabel) unstack  ///
		collabels(none) label star(* 0.10 ** 0.05 *** 0.01) ///
		order(1.intervention#1.tfsa_cat 1.intervention#2.tfsa_cat 2.intervention#1.tfsa_cat 2.intervention#2.tfsa_cat) ///
		keep(1.intervention#1.tfsa_cat 1.intervention#2.tfsa_cat 2.intervention#1.tfsa_cat 2.intervention#2.tfsa_cat) ///
		sub(\_ _   "Means-testing arm $\times$ \(\qquad\)Mostly TFSA" "Means-testing arm $\times$ Mostly TFSA" ///
		"Means-testing arm $\times$ \(\qquad\)Mostly RRSP" "Means-testing arm $\times$ Mostly RRSP" ///
		"Tax arm $\times$ \(\qquad\)Mostly TFSA" "Tax arm $\times$ Mostly TFSA" ///
		"Tax arm $\times$ \(\qquad\)Mostly RRSP" "Tax arm $\times$ Mostly RRSP" ///
		"Means-testing arm" "\(\qquad\)Means-testing arm" "Tax arm" "\(\qquad\)Tax arm" 1.educ_some_uni "Some university" 1.educ_bach_more "Bachelor degree+" ///
		"#" "\(\times\)"  Constant "\(\qquad\)Constant" ) ///
		cells("b(fmt(a2)star)" "se(fmt(a2)par)" ) nonum  nogaps eqlabels(none) 
		
		
		
		*****************************************************************************
		* Table OA.3: Tabulation of Financial Literacy and Knowledge Scores.        *
		* AND Rank correlation analysis between Financial literacy and Tax Literacy *
		*****************************************************************************
		
		* Correlation (Spearman rank corr)
		spearman finlit_index know_score if tag
		spearman finlit_index know_score if tag & treat==0
		spearman finlit_index know_score if tag & treat==1
		spearman finlit_index know_score if tag & treat==2

		
		* Correlation (kendall rank corr)
		ktau finlit_index know_score if tag
		ktau finlit_index know_score if tag & treat==0
		ktau finlit_index know_score if tag & treat==1
		ktau finlit_index know_score if tag & treat==2

		
		gen knowscore=know_score
		recode knowscore (0=0) (0.2=1) (0.4=2) (0.6=3) (0.8=4) (1=5)
		label def knowscore 0 "0" 1 "1"  2 "2" 3 "3" 4 "4" 5 "5"
		label val knowscore knowscore
		
		estpost tab  knowscore finlit_index
		est store tabs
		
		* Export
		esttab tabs using "tables_figures/corr_tab.tex", replace cell(colpct(fmt(2))) unstack noobs label f plain booktabs b(3) p(3) ///
		refcat(0.finlit_index "\textit{Financial Literacy}" )
